Skip to content

ecs 0.7.0: SIMD lanes at storage precision across rows, filtered rows and large arms - #288

Merged
krisnye merged 1 commit into
mainfrom
krisnye/simd-lanes
Nov 28, 2026
Merged

krisnye merged 1 commit into
mainfrom
krisnye/simd-lanes

Conversation

@krisnye

@krisnye krisnye commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

@adobe/ecs 0.7.0: compiled kernels run in SIMD lanes in many more cases, at storage precision.

Behavior change: every compiled kernel's WASM now computes at storage precision, not only kernel: true ones. Arithmetic on F32 fields rounds each step to f32, in lanes and one row at a time alike, so every row gets the same bits whether or not it falls in a group of 4. number fields compute in f64. The JS kernel still computes as written. The kernel doc in declaration.ts, guide chapter 14 and design.md are updated.

What changed

  • Temporaries written into their reads (forward-locals.ts): nested calls such as Vec3.add(p, Vec3.scale(v, d)) now run as whole elements across rows.
  • Across rows: per-row values (a mass) are spread across each element's fields with shuffles; per-row locals are computed 4 rows at a time; fields a store leaves, and padding, are blended back; f64 components use f64x2 lanes.
  • Filtered rows (changed): run 4 rows at a time under masks from the rows' change ticks. Masks cover 8 rows at once; 8 rows with no change are skipped whole. No branch per row.
  • One row at a time: f32 arithmetic uses f32 instructions, and values the same for every row are converted once per call.
  • Interleaved loop: if arms over the size budget are skipped in groups of 4 where no row takes them, with the fields only that arm uses loaded inside it, instead of the whole kernel falling back to one row at a time.
  • Docs: describe labels interleaved kernels correctly. New component-modeling rules in rules/component.x.ts.md, with a pointer in the architecture standard. perf.md records the measurements behind them.

Results (M4 Max, one thread, ns/row unless noted)

Before After
integrate (guide pattern, 1M) 0.951 0.273
integrate f64 0.791 0.522
integrate changed half (new) 1.11 0.49
changed all 100K kernels (µs per system) 64.5 26.5
sparse changed 0.177 0.155
guide move, WASM without SIMD 1.95 0.61
ecs_benchmark MoreComplexSystem (1M) 0.95 0.76

The guide's move with SIMD runs at 0.227 ns/row, the same as its loads and stores alone, which is one core's memory throughput. Our ecs_benchmark comparison against the C++ libraries otherwise stays within noise: its systems are line-for-line ports that were already kernel: true.

Tests

  • Filtered kernels: with SIMD and without, bit for bit (values, row, chunk and block ticks), across scattered, dense, alternating and clustered changes, unaligned ranges, Vec3/Vec4/f64 elements, partial stores and ifs.
  • forward-locals.test.ts, the new across-rows cases, the comparison-rounding regression, and interleaved-arms.test.ts.
  • Precision specs rewritten for the new rule: WASM matches the body rounding each f32 step; JS matches the body as written.
  • pnpm run build and pnpm test at the ecs root, plus check:workspace, typecheck, lint, docs and build at both roots, all pass locally.

… rows, filtered rows and large arms

- Every compiled kernel's WASM computes at storage precision: F32 arithmetic rounds each step to f32, in lanes and a
  row at a time alike, a row at a time in f32 instructions; number fields compute in f64, in f64x2 lanes.
- Locals assigned once are written into their reads before planning, so nested calls such as
  Vec3.add(p, Vec3.scale(v, d)) run as whole elements across rows: integrate 0.95 -> 0.27 ns a row.
- Across rows: per-row values spread over each element's leaves, per-row locals, kept lanes for partial stores and
  padding, f64 elements.
- Filtered rows run across rows under eight rows' masks of passing ticks: integrate changed half 1.11 -> 0.49 ns,
  changed all 100K kernels 64.5 -> 26.5 us.
- Interleaved arms past the budget are skipped by groups no row takes them, their spans loaded in the arm.
- Component modeling rules, and perf.md's measurements behind them.

Co-Authored-By: OpenCode <noreply@opencode.ai>
@krisnye
krisnye merged commit d40ecc1 into main Nov 28, 2026
4 checks passed
@krisnye
krisnye deleted the krisnye/simd-lanes branch November 28, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant